<template>
  <div class="carousel-container">
    <div class="carousel-with-thumbs">
      <!-- Main Carousel -->
      <el-carousel
        ref="mainCarousel"
        indicator-position="none"
        height="100%"
        :autoplay="false"
        @change="handleSlideChange"
      >
        <el-carousel-item v-for="(item, index) in imgs" :key="index">
          <div class="slide-content">
            <img :src="item.url" :alt="'Slide ' + (index + 1)">
            <div class="slide-title">{{ item.title }}</div>
            <div class="slide-subtitle" v-if="item.subtitle">{{ item.subtitle }}</div>
          </div>
        </el-carousel-item>
      </el-carousel>

      <!-- Thumbnail Navigation - Positioned absolutely on top -->
      <div class="thumbnails">
        <div
          v-for="(item, index) in imgs"
          :key="'thumb-' + index"
          class="thumbnail-item"
          :class="{ 'active': activeIndex === index }"
          @mouseenter="goToSlide(index)"
        >
          <div class="thumbnail-content">
            <img :src="item.url" :alt="'Thumbnail ' + (index + 1)">
            <div class="thumbnail-label">{{ item.title }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import img1 from '@/assets/imgs/master_view/loop_bg1.png'
import img2 from '@/assets/imgs/master_view/loop_bg2.png'
import img3 from '@/assets/imgs/master_view/loop_bg3.png'
import img4 from '@/assets/imgs/master_view/loop_bg4.png'

const imgs = [
  {
    url: img1,
    title: '第5人格',
    subtitle: '2025英雄联盟MSI'
  },
  {
    url: img2,
    title: 'KPL夏季赛'
  },
  {
    url: img3,
    title: '2025VCTCN第二赛段'
  },
  {
    url: img4,
    title: '2025IVL夏季赛',
    subtitle: '常规赛火热进行中!'
  }
];

const mainCarousel = ref(null);
const activeIndex = ref(0);

const handleSlideChange = (index) => {
  activeIndex.value = index;
};

const goToSlide = (index) => {
  mainCarousel.value.setActiveItem(index);
};
</script>

<style scoped lang="scss">
.carousel-container {
  width: 100%;
  height: 500px; /* Adjust height as needed */
  position: relative;

  .carousel-with-thumbs {
    display: flex;
    height: 100%;
    position: relative;

    /* Main Carousel Styles */
    :deep(.el-carousel) {
      width: 100%;
      height: 100%;

      .el-carousel__container {
        height: 100%;
      }

      .slide-content {
        position: relative;
        height: 100%;

        img {
          width: 100%;
          height: 100%;
          object-fit: cover;
        }

        .slide-title {
          position: absolute;
          top: 30px;
          left: 30px;
          color: white;
          font-size: 32px;
          font-weight: bold;
          text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
        }

        .slide-subtitle {
          position: absolute;
          top: 70px;
          left: 30px;
          color: white;
          font-size: 18px;
          text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
        }
      }
    }

    /* Thumbnail Styles - Positioned absolutely on top right */
    .thumbnails {
      position: absolute;
      top: 20px;
      right: 20px;
      width: 200px;
      display: flex;
      flex-direction: column;
      gap: 10px;
      z-index: 2;

      .thumbnail-item {
        position: relative;
        height: 60px;
        cursor: pointer;
        border-radius: 4px;
        overflow: hidden;
        transition: all 0.3s ease;
        box-shadow: 0 2px 8px rgba(0,0,0,0.2);

        &.active {
          transform: scale(1.05);
          box-shadow: 0 0 0 2px #409EFF;
        }

        &:hover {
          transform: scale(1.05);
        }

        .thumbnail-content {
          position: relative;
          width: 100%;
          height: 100%;

          img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }

          .thumbnail-label {
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            background: rgba(0, 0, 0, 0.7);
            color: white;
            padding: 5px 8px;
            font-size: 12px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
          }
        }
      }
    }
  }
}
</style>
